Menu General Batch Technical Nomenclature
Page 1
Index
Index | -Menu-            


General Batch Technical Nomenclature

The glossary of the terms that we commonly use in posts.

The stuff under the main links below is written by William Allen so
I will examine all the links. I toke a look yesterday at no 6 below
about the Synthetic Environment Variable. My batching about a topic
is linked below under a main link as no 01, 02 and so... Hmmm, both
the ExitPrompt and the BennyLevel seems to be known stuff, somehow?


     01-00  ExitPrompt
                News, page 5     -- Old but p.t. newest.
     02-00  Inception
     03-00  Universal Prefixer
     04-00  Batch Subroutine
     05-00  Hybrid Name
     06-00  Synthetic Environment Variable
        01      06-01    
        02      06-02    
     07-00  BennyLevel
                News, page 4     -- Very old (year 2001)
     08-00  Bouncing off the Prompt
        01      08-01            How to get an input with Enter.
        02      08-02            How to get an input with Enter. Recursive.
        03      08-03            List of files.
        04      08-04            List proceeding, any list.
     09-00  XCOPY cyclic error suppression
     10-00  CHOICE Streaming Parser


General Batch Technical Nomenclature used here
==============================================

This is a list of some of the Batch-related Technical terms coined
or used by the team here, and for which detailed documentation
on the technique and/or subject has been posted to Usenet by us.
A link to a relevant, detailed Usenet post is included for each term.


1) ExitPrompt
Use of syntax such as:
ECHO.EXIT|%COMPSPEC%/k PROMPT $LCustom Prompt Echo$G$_|find " "
to ECHO a customised prompt to screen or redirect to file

Explanation/examples of the ExitPrompt technique:
News
Date: 7 Oct 2001


2) Inception
Use of the first token on a text line as a temporary Batch name
to enable the remaining tokens on the line to be accessed as
command-line parameters when the line is "executed" as a script.

Explanation of Inceptive Intermediary Batch file technique
News
Date: 9 Apr 2001


3) Universal Prefixer
Use of file containing, say SET VAR= with no terminal carriage-return
or linefeed so that any appended text appears on the same line. The
result normally used to load line of text from file into environment
variable.

Universal prefixer (Line of text from file into environment variable)
News
Date:  24 Apr 2001


4) Batch Subroutine
A Batch subroutine is a chunk of Batch code, isolated from
the rest of the script by a GOTO EOF instruction that "jumps"
over it in normal use, unless it's specifically CALLed.
An initial subroutine handler line is used, thus:

  @ECHO OFF
  IF (GOTO:)==(%1) %1%2 (Subroutine handler)

  :: Application code goes here

  GOTO EOF (=Subroutine code follows=)
  :_SRNAME (Usage: CALL %0 GOTO: _SRNAME parameters)
  :: Canonical format for local subroutine labels:
  :1_SRNAME (Description of label)

  :EOF (End-of-file)

The Subroutine handler is transparent to normal Batch parameters,
but intercepts all subroutine calls. There can be many such Subroutines
in any particular Batch script; they remain independent of each other.

Explanation of Subroutine syntax (using Date/time Subroutine)
News
Date: 21 May 2001


5) Hybrid Name
A long file name that would fit the 8.3 short name format but has been
created as a long file name (usually by failing to capitalise filename
when initially creating file). Occupies two folder index entries taking
64-bytes instead of the usual single 32-byte folder entry. A "bad thing".

Hybrid names in Windows 9x - script demo and explanation
News
Date: 22 May 2001


6) Synthetic Environment Variable
  06-00
  Links: 06-01 | 06-02

An environment variable that is created by splitting a special PROMPT
string by punching a NULL (ASCII=0) hole in it. Unlike the normal SET
variables, a synthetic variable can be created with [=] [|] [>] and [<]
characters in it.

Several environment variables each with the same name (Synthetic Environment
Variables)
News
Date: 22 Nov 2000


7) BennyLevel
Use of IF ERRORLEVEL test with non-numerics or test numbers beyond 255.
The results are interpreted modulo 256. Non-numerics are interpreted as
if they were single decimal "digits" with value equal to ASCIIValue-48
(known as their BennyValue).

The arithmetic of BennyLevel ERRORLEVEL checking
News
Date: 20 Nov 2000


8) Bouncing off the Prompt
  08-00
  Links: 08-01 | 08-02 | 08-03 | 08-04

The list processing technique that depends on copying a list to a temporary
Batch script, and "executing" the result as a series of "bad commands" in
a child COMMAND shell with a custom PROMPT. If all is well, each line of
the list "bounces" as a bad command, instead of being executed. The captured
result is the list prefixed with the custom prompt.

List processing or Bouncing off the PROMPT (LONG)
News
Date: 17 Nov 2001


9) XCOPY cyclic error suppression
The use of XCOPY with the /L (=list only) command to copy a fileset into
itself (but without generating a "cyclic copy error"). The resulting list
is normally very easy to process by "Bouncing off the Prompt".

XCOPY whole-disk listings without a cyclic copy error
News
Date: 3 Nov 2001


10) CHOICE Streaming Parser
Streaming text string through CHOICE command to remove all but
a (small subset) of characters. Differs from usual CHOICE parsing
in that [/] and [Space] characters can be elided. Demo script:

====Begin cut-and-paste (omit this line)
  @ECHO OFF
  IF (GOTO:)==(%1) %1%2 (Subroutine handler)
  ECHO.Initial text: 1Text2Text//3Text\\
  SET VAR=
  ECHO.1Text2Text//3Text\\&|%COMSPEC%/c %0 GOTO: _TM>TEMP.BAT
  FOR %%C IN (CALL DEL) DO %%C TEMP.BAT
  ECHO.CHOICE streaming parser result=%VAR%
  SET VAR=

  GOTO EOF (=Subroutine code follows=)
  :_TM
  CHOICE /C&0123456789 /n>NUL
  FOR %%N IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL 77%%N SET V=%%N
  IF ERRORLEVEL 2 SET VAR=%VAR%%V%
  IF ERRORLEVEL 2 GOTO _TM
  ECHO.SET VAR=%VAR%

  :EOF (End-of-file)

====End cut-and-paste (omit this line)
To use the code above, cut-and-paste the text between the ==== lines
into a file with extension .BAT and base name of your choice. Lines
that don't begin with two spaces have wrapped in transmission. The
Batch code above was written and tested in the Win9x GUI.

Documentation of CHOICE streaming parser
News
Date: 8 Dec 2001
(This thread also includes details of how to debug this method, which
is not easy to do by standard Batch error debugging methods)

--
(pp) William Allen



Synthetic Environment Variable
  06-01
  Links: 06-00 | 06-02

Based on the discovery by William Allen.
Construction under Win98 by Benny Pedersen,

@ECHO PROMPT %PROMPT%>      %temp%.\~.tmp
@ECHO off                                         >%temp%.\~.scr
FOR %%c in (L2 w0 f1Lfff''1a L0 w2 q) do ECHO %%c>>%temp%.\~.scr
DEBUG.EXE                   %temp%.\~.tmp     >NUL<%temp%.\~.scr
TYPE                        %temp%.\~.tmp     >    %temp%.\~.bat

ECHO e100 0'VAR==' 0'VAR=was' 0'VAR=equal' d a>    %temp%.\~.scr
FOR %%c in (rcx 1a w100 q26bytes) do ECHO %%c>>    %temp%.\~.scr
DEBUG.EXE                   %temp%.\~.tmp     >NUL<%temp%.\~.scr

COPY /b %temp%.\~.bat   +   %temp%.\~.tmp     >NUL
DELTREE /y                  %temp%.\~.tmp     >NUL %temp%.\~.scr
FOR %%f in (CAL DE) do %%fL %temp%.\~.bat

:VAR
  ECHO. (VAR) = (%VAR%)
  SET VAR=
IF NOT (%VAR%)==() GOTO VAR


Synthetic Environment Variable
  06-02
  Links: 06-00 | 06-01

Based on the discovery by William Allen.
Construction under Win98 by Benny Pedersen,

@ECHO off
ECHO PROMPT %%PROMPT%%!CMDLINE=SET X=Y>%temp%.\~.bat
ECHO :EXIT|%COMSPEC%/kPROMPT e10f 0$_w$_q|debug %temp%.\~.bat>NUL
FOR %%c in (CAL DE) do %%cL %temp%.\~.bat
SET CMDLINE=
ECHO. Your variable is: %CMDLINE%

  echo.
% Get name and value.%  SET|FIND "CMDLINE"
  pause
% Put other contents.%  SET CMDLINE=New Contents
% Get name and value.%  SET|FIND "CMDLINE"
  pause
% Put other contents.%  FIND ""<NUL
% Get name and value.%  SET|FIND "CMDLINE"
  pause
% Put other contents.%  SET CMDLINE=New Contents.
% Get name and value.%  SET|FIND "CMDLINE"
  pause

GOTO EOF
    To access the variable named CMDLINE, it must (as shown!),
    first be cleared (the last synthetic variable in the stack
    would be non synthetic, i.e. be the first in the front and
    as an ordinary variable), then our second setting would be
    accessible. So the value of the second setting above which
    is now accessible in the front would remain only until you
    perform something else; for example, executing a "FIND" or
    a "SORT", FC.EXE... or, if you simply putting a new value.

    Benny Pedersen,
    PS.
    If you put a value in Y, then you could assign X something
    like this:
                ECHO. (X) is (%X%)
                %CMDLINE%
                ECHO. (X) is (%X%)
    along with
    substitute
         this:  %%PROMPT%%!CMDLINE=SET X=Y
         with:  %%PROMPT%%!CMDLINE=SET X=%Y%
:EOF


Bouncing off the Prompt
  08-01
  Links: 08-00 | 08-02 | 08-03 | 08-04

How to get an input followed by Enter.

-- Ver no 1:  7 lines and 219 bytes. 3 pipes.
-- Used EXE:  fc, find and debug.
-- Comments:  Not recursive. No GOTO's.

@ECHO OFF
ECHO Input,
fc/N/LB1 NUL CON|find "1: ">%temp%.\$.BAT
ECHO EXIT|%COMSPEC%/KPROMPT E102'SET Y='$_W$_Q|debug %temp%.\$.BAT>NUL
FOR %%C IN (CAL DE) DO %%CL %temp%.\$.BAT
ECHO. The variable Y is %Y%
SET Y=

-- Variation  12 lines and 351 bytes. 2 pipes.
-- Used EXE:  fc and find.

  @ECHO OFF
  ECHO @PROMPT SET Y=>              %temp%.\$.BAT
  ECHO Input,
  fc /N/LB1 NUL CON | find " 1: " >>%temp%.\$.BAT
  CTTY NUL
  %COMSPEC%/C%temp%.\$.BAT|find ":">%temp%.\$.BAT
  CTTY CON
  FOR %%C IN (CAL DE) DO %%CL       %temp%.\$.BAT
  FOR %%! in (%Y%) do SET Y=%%!
  IF 1:==%Y% SET Y=
  ECHO. The value of Y is %Y%
  SET Y=

No input; alternative for the 3'th last line:  IF 1:==%Y% %0

Transform the first letter to uppercase, Win9x, (Page 11, ONLY %ComSpec%).
Substitute the last 2 lines with the following:

  ECHO.%Y%.|CHOICE/cabcdefghijklmnopqrstuvwxyz.>NUL
  FOR %%c in (a b c d e f g h i j k l m) do IF ERRORLEVEL x%%c SET L=%%c
  FOR %%c in (n o p q r s t u v w x y z) do IF ERRORLEVEL x%%c SET L=%%c
  FOR %%%L% in (/%L%) do SET Y=%%%%%Y%
  FOR %%"/" in (" ")  do SET Y=%Y%
  FOR %%%%  in (" ")  do SET Y=%Y%
  FOR %%c   in (%Y%)  do SET Y=%%c
  ECHO. The value of Y is %Y%
  FOR %%c in (L Y) do SET %%c=

Benny Pedersen,
BTW. If you want an input of 1 or 2 words instead of 1 word,
then you may substitute the last 4 lines with the following:

  FOR %%! in (%Y%) do SET Y1=%%!
  IF 1:==%Y1% SET Y1=
::IF 1:==%Y1% %0
  FOR %%! in (%Y%) do IF NOT %%!==1: IF NOT %%!==%Y1% SET Y1=%%! %Y1%
  ECHO The value (%%Y1%%) is (%Y1%).
  FOR %%! in (Y Y1) do SET %%!=


Bouncing off the Prompt
  08-02
  Links: 08-00 | 08-01 | 08-03 | 08-04

How to get an input followed by Enter.

-- Ver no 2:  14 lines and 306 bytes. 2 pipes.
-- Used EXE:  fc and find.
-- Comments:  Recursive.

@ECHO OFF
%1 %2 %COMSPEC%/C%0 GOTO Input %temp%.\$.BAT
FOR %%C IN (CAL DE) DO %%CL    %temp%.\$.BAT
ECHO. The variable Y is %Y%
:!
FOR %%C IN (SET GOTO:EOF) DO %%C Y=%4
:Input
PROMPT CALL %0 %1 !
ECHO %2,
CTTY NUL
fc/N/LB1 NUL CON|find " 1: ">%3
%COMSPEC% /C %3 |find " 1: ">%3
CTTY CON
:EOF

: Links: InputBox.


Bouncing off the Prompt
  08-03
  Links: 08-00 | 08-01 | 08-02 | 08-04

-- List proceeding, (files),

This batch file would be searching an entire drive. Put
into the variable Y, each name of any batch file, which
was found, one by one, and then echoing the value of Y.

Both the quote in the "%%%% and in the Y=%4" are significant
but you can examine the result without using those "quotes".

@ECHO OFF
%1 %2 SET Y=
%COMSPEC% /C%0 GOTO F-List D          %temp%.\{LIST}.BAT
FOR %%_ IN (CALL DEL GOTO:EOF) DO %%_ %temp%.\{LIST}.BAT
:F-List
DIR %3:\*.BAT /S/B | find /N ":" >%4
CTTY NUL
PROMPT CALL %0 %1 FSC %3 "%%%%
%COMSPEC%/C %4|find "]%3:" >%4
FOR %%C IN (CTTY GOTO:EOF) DO %%C CON
:FSC
    IF !==%Y%! FOR %%[ IN (%%) DO SET Y=%4"
    FOR %%1 IN (%%) DO SET Y=%Y%
    FOR %%2 IN (%%) DO SET Y=%Y%
    FOR %%3 IN (%%) DO SET Y=%Y%
    FOR %%4 IN (%%) DO SET Y=%Y%
    FOR %%5 IN (%%) DO SET Y=%Y%
    FOR %%6 IN (%%) DO SET Y=%Y%
    FOR %%7 IN (%%) DO SET Y=%Y%
    FOR %%8 IN (%%) DO SET Y=%Y%
    FOR %%9 IN (%%) DO SET Y=%Y%
    FOR %%0 IN (%%) DO SET Y=%Y%
    FOR %%] IN (%%) DO SET Y=%Y%
    ECHO %Y% | find "]%3:" > NUL
    IF NOT ERRORLEVEL 1 GOTO FSC
::  FOR %%%3 IN (%3) DO ECHO.%Y%
    FOR %%%3 IN (%3) DO SET Y=%Y%
    ECHO.%Y%
    SET Y=
:EOF


Bouncing off the Prompt
  08-04
  Links: 08-00 | 08-01 | 08-02 | 08-03

-- List proceeding, (any list),

@ECHO OFF
%1 %2 SET Y=
ECHO. Could it be any list! >                     %temp%.\{LIST}.BAT
FOR %%C in (mir dir me my ! ? 1 A a) do ECHO %%C>>%temp%.\{LIST}.BAT
%COMSPEC%/C%0 GOTO X-List             %temp%.\{LIST}.BAT
FOR %%C IN (CALL DEL GOTO:EOF) DO %%C %temp%.\{LIST}.BAT
:X-List
TYPE %3 |find /V/N "//\//"> %3
CTTY NUL
PROMPT CALL %0 %1 FSC "%%%%
%COMSPEC%/C %3 | find "]" > %3
FOR %%C IN (CTTY GOTO:EOF) DO %%C CON
:FSC
    IF !==%Y%! FOR %%[ IN (%%) DO SET Y=%3"
    FOR %%1 IN (%%) DO SET Y=%Y%
    FOR %%2 IN (%%) DO SET Y=%Y%
    FOR %%3 IN (%%) DO SET Y=%Y%
    FOR %%4 IN (%%) DO SET Y=%Y%
    FOR %%5 IN (%%) DO SET Y=%Y%
    FOR %%6 IN (%%) DO SET Y=%Y%
    FOR %%7 IN (%%) DO SET Y=%Y%
    FOR %%8 IN (%%) DO SET Y=%Y%
    FOR %%9 IN (%%) DO SET Y=%Y%
    FOR %%0 IN (%%) DO SET Y=%Y%
    FOR %%] IN (%%%%) DO SET Y=%Y%
    ECHO %Y% | find "]" > NUL
    IF NOT ERRORLEVEL 1 GOTO FSC
    FOR %%%% IN (.) DO SET Y=%Y%
    FOR %%C IN (%Y%) DO SET Y=%%C
    ECHO%Y%
    SET Y=
:EOF


-Top-